<?php

class Default_Model_Yatzy_XresultMapper extends Default_Model_Yatzy_ResultMapper
{
    public function getDbTable()
    {
        if (null === $this->_dbTable) {
            $this->setDbTable('Default_Model_Yatzy_DbTable_Result');
        }
        return $this->_dbTable;
    }
	
	public function getTopTen() {
        $resultSet = $this->getDbTable()->fetchTopTen();
		$results   = array();
        foreach ($resultSet as $row) {
            $result = new Default_Model_Yatzy_Xresult();
            $result	->setId($row->spagooy_result_id)
                  	->setSum($row->spagooy_result_total)
                  	->setUserId($row->spagooy_result_user_id)
				  	->setFirstName($row->spagooy_user_first_name)
				  	->setLastName($row->spagooy_user_last_name)
				 	 ->setEmail($row->spagooy_user_email)
                 	 ->setMapper($this);
            $results[] = $result;
        }
        return $results;
	}
	
	public function getTopPlayers()
	{
        $resultSet = $this->getDbTable()->fetchTopTenPlayers();
		$results   = array();
        foreach ($resultSet as $row)
		{
            $result = new Default_Model_Yatzy_Xresult();
            $result	->setId($row->spagooy_result_id)
                  	->setSum($row->best_res)
                  	->setUserId($row->spagooy_result_user_id)
				  	->setFirstName($row->spagooy_user_first_name)
				  	->setLastName($row->spagooy_user_last_name)
				 	 ->setEmail($row->spagooy_user_email)
                 	 ->setMapper($this);
            $results[] = $result;
        }
        return $results;
	}
	
	public function getAverage()
	{
        $resultSet = $this->getDbTable()->fetchTopAverage();
		
		$results   = array();
        foreach ($resultSet as $row) {
            $result = new Default_Model_Yatzy_Xresult();
            $result	->setUserId($row['spagooy_user_id'])
					->setFirstName($row['spagooy_user_first_name'])
					->setLastName($row['spagooy_user_last_name'])
				  	->setEmail($row['spagooy_user_email'])
					->setSum(round($row['average']))
              
                  	->setMapper($this);
            $results[] = $result;
		}
		return $results;
	}
	
	public function getGamesPlayed()
	{
        $resultSet = $this->getDbTable()->fetchGamesPlayed();
		
		$results   = array();
        foreach ($resultSet as $row) {
            $result = new Default_Model_Yatzy_Xresult();
            $result	->setUserId($row['spagooy_user_id'])
					->setFirstName($row['spagooy_user_first_name'])
					->setLastName($row['spagooy_user_last_name'])
				  	->setEmail($row['spagooy_user_email'])
					->setSum($row['games'])
              
                  	->setMapper($this);
            $results[] = $result;
		}
		return $results;
	}
/*
    public function find($id, Default_Model_Guestbook $guestbook)
    {
        $result = $this->getDbTable()->find($id);
        if (0 == count($result)) {
            return;
        }
        $row = $result->current();
        $guestbook->setId($row->id)
                  ->setEmail($row->email)
                  ->setComment($row->comment)
                  ->setCreated($row->created);
    }

    public function fetchAll()
    {
        $resultSet = $this->getDbTable()->fetchAll();
        $entries   = array();
        foreach ($resultSet as $row) {
            $entry = new Default_Model_Guestbook();
            $entry->setId($row->id)
                  ->setEmail($row->email)
                  ->setComment($row->comment)
                  ->setCreated($row->created)
                  ->setMapper($this);
            $entries[] = $entry;
        }
        return $entries;
    }
*/

}
